package com.uu.it.tracker;

import com.android.tracker.R;
import com.uu.it.tracker.preferences.PersonalInfoMenu;
import com.uu.it.tracker.preferences.TwitterSettingsMenu;
import com.uu.it.tracker.views.ResultsView;
import com.uu.it.tracker.views.RunView;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.TabHost;
import android.content.Intent;

/**
 * An example of tab content that launches an activity via {@link android.widget.TabHost.TabSpec#setContent(android.content.Intent)}
 */
public class Tracker extends TabActivity {
	
	private static final int MENU_PREFERENCES = 1;
	private static final int MENU_ABOUT = 2;
	//private static final int MENU_QUIT = 3;
	private static final int SUBMENU_PERSONALINFO = 4;
	private static final int SUBMENU_TWITTERSETTINGS = 5;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.main);

        final TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("Run",
                		getResources().getDrawable(R.drawable.tabicon_run_unselected))
                .setContent(new Intent(this, RunView.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("Results",
                		getResources().getDrawable(R.drawable.tabicon_results_unselected))
                .setContent(new Intent(this, ResultsView.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
     
        
        
        tabHost.setCurrentTabByTag("tab1");
        
    }
    /* Creates the menu items */
      public boolean onCreateOptionsMenu(Menu menu) {
    	boolean result = super.onCreateOptionsMenu(menu);
    	
        menu.add(0, MENU_ABOUT, 2, "About");	
        //menu.add(0, MENU_QUIT, 3, "Exit");  
        SubMenu preference_submenu = menu.addSubMenu(0,MENU_PREFERENCES,1,"Preferences");
        
        
        MenuItem personalinfo_menuitem = preference_submenu.add(1,SUBMENU_PERSONALINFO,1,"Personal info");
        MenuItem twittersettings_menuitem = preference_submenu.add(1,SUBMENU_TWITTERSETTINGS,2,"Twitter settings");
        
        personalinfo_menuitem.setIntent(new Intent(this,  PersonalInfoMenu.class));
        twittersettings_menuitem.setIntent(new Intent(this, TwitterSettingsMenu.class));
        
        return result;
    }
    
    /* Handles item selections */
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case MENU_PREFERENCES:
            
            return true;
        case MENU_ABOUT:
        	AlertDialog.Builder alert = new AlertDialog.Builder(this);
    		alert.setTitle("About");
    		alert.setMessage("Welcome to Walkometer application. This shows you your status whether you" +
    				" are walking or running or staying idle. Click on the Results tab to see your daily " +
    				"statistics. Click on preferences to change your Settings"); 
    		alert.show();
            return true;
        
        }
        return false;
    }
}
